home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 3_0 / MDEF__ / XFER_MDE.C < prev   
C/C++ Source or Header  |  1987-11-28  |  2KB  |  79 lines

  1. #include "MacTypes.h"
  2. #include "stdio.h"
  3.  
  4. /*
  5.     Quick and dirty code to extract the MDEF resource id of 130 from the
  6.     file "MDEF Code", and place it into the "SHELL.RSRC" file.  Nothing in
  7.     the way of error-checking going on here.  Obviously, all files must
  8.     be in the same HFS folder, otherwise you'll need to put full path
  9.     names in the OpenResFile() calls.
  10. */
  11.  
  12. main()
  13. {
  14.     int        thefile;
  15.     Handle    theres,oldres;
  16.     char    ch;
  17.     
  18.     Click_On(FALSE);
  19.     printf("\fResource Manager Call      Resource Error");
  20.     printf("\n---------------------      --------------");
  21.     thefile = OpenResFile("\pMDEF Code");
  22.     perr("OpenResFile",ResError());
  23.     theres = GetResource('MDEF',130);
  24.     perr("GetResource",ResError());
  25.     DetachResource(theres);
  26.     perr("DetachResource",ResError());
  27.     CloseResFile(thefile);
  28.     perr("CloseResFile",ResError());
  29.     
  30.     thefile = OpenResFile("\ppatmenudemo.rsrc");
  31.     perr("OpenResFile",ResError());
  32.     oldres = GetResource('MDEF',130);
  33.     perr("GetResource",ResError());
  34.     if (oldres != 0L){
  35.         RmveResource(oldres);
  36.         perr("RmveResource",ResError());
  37.     }
  38.     AddResource(theres,'MDEF',130,"\pPattern Menu");
  39.     perr("AddResource",ResError());
  40.     CloseResFile(thefile);
  41.     perr("CloseResFile",ResError());
  42.     printf("\n\n\nFinished.  Press Any Key");
  43.     do{
  44.     }
  45.     while( (ch = getchar()) =='');
  46. }
  47.  
  48. perr(astr,errcode)
  49. char    *astr;
  50. int        errcode;
  51. {
  52.     char    *errinterp[80];
  53.     
  54.     printf("\n%16s%20d",astr,errcode);
  55.     if (errcode != 0){
  56.         finderr(errcode,errinterp);
  57.         printf("%30s",errinterp);
  58.     }
  59. }
  60.  
  61. finderr(errcode,interpretation)
  62. int        errcode;
  63. char    *interpretation;
  64. {
  65.     switch(errcode){
  66.         case -192:        strcpy(interpretation,"resNotFound");
  67.                         break;
  68.         case -193:        strcpy(interpretation,"resFNotFound");
  69.                         break;
  70.         case -194:        strcpy(interpretation,"addResFailed");
  71.                         break;
  72.         case -196:        strcpy(interpretation,"rmvResFailed");
  73.                         break;
  74.         case -43:        strcpy(interpretation,"fnfErr");
  75.                         break;
  76.         default:        strcpy(interpretation,"undefined error");
  77.                         break;
  78.     }
  79. }